package com.atguigu.stuty.cas;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * @Author early morning
 * @Create 2025/4/24 20:08
 * @Description: CAS
 * compare and swap
 * 内存位置、预期原值及更新值
 */
public class CasHello {
    public static void main(String[] args) {
        AtomicInteger atomicInteger = new AtomicInteger(5);
        System.out.println(atomicInteger.get());

        // 预期值和内存位置的值相等返回 true
        System.out.println(atomicInteger.compareAndSet(5,2025)+ "\t" + atomicInteger.get());
        System.out.println(atomicInteger.compareAndSet(5,10000)+ "\t" + atomicInteger.get());

        System.out.println(atomicInteger.incrementAndGet()); // 2026
        System.out.println(atomicInteger.getAndIncrement() + "\t" + atomicInteger.get()); // 2027

        System.out.println(atomicInteger.addAndGet(3));


    }
}
